package com.itheima.pinda.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MP 相关配置类
 *
 * @author llhuang10
 * @date 2021/9/29 15:08
 */
@Configuration
@MapperScan(basePackages = "com.itheima.pinda.mapper")
public class MybatisPlusConfig {


    /**
     * MP 分页配置
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * Mybatis Plus 注入器
     * 公共的字段, id, create_user, create_time, update_user, create_time
     *
     * @param idGenerator
     */
    @Bean
    public MetaObjectHandler metaObjectHandler(CustomIdGenerator idGenerator) {
        return new MyMetaObjectHandler(idGenerator);
    }
}
